<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            background-color: #eee;
        }
    </style>
</head>

<body>
    <div>测试</div>
    <canvas width="400" height="400"></canvas>
    <script>
        var canvas = document.querySelector("canvas");
        var ctx = canvas.getContext("2d");
        ctx.fillStyle = "red";
        ctx.beginPath();
        ctx.arc(200, 200, 100, 0, Math.PI * 2);
        ctx.fill();
        ctx.fillStyle="#162fff";
        ctx.beginPath();
        ctx.fillRect(10,10,20,30);
        ctx.fill();
        ctx.fillStyle="#000";
        ctx.beginPath();
        ctx.strokeRect(10,100,20,30);
        ctx.fill();
        ctx.fillStyle = "red";
        ctx.beginPath();
        ctx.clearRect(200,200,20,50);
        ctx.fill();
    </script>
</body>

</html>